Passed
Pull Request — master (#84)
by Mathieu
01:21
created

User.getEntryDate   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import {Entity, Column, PrimaryGeneratedColumn, Index} from 'typeorm';
2
3
export enum UserRole {
4
  COOPERATOR = 'cooperator',
5
  ACCOUNTANT = 'accountant'
6
}
7
8
@Entity()
9
export class User {
10
  @PrimaryGeneratedColumn('uuid')
11
  private id: string;
12
13
  @Column({type: 'varchar', nullable: false})
14
  private firstName: string;
15
16
  @Column({type: 'varchar', nullable: false})
17
  private lastName: string;
18
19
  @Column({type: 'varchar', unique: true, nullable: false})
20
  private email: string;
21
22
  @Index('api-token')
23
  @Column({type: 'varchar', nullable: true})
24
  private apiToken: string;
25
26
  @Column({type: 'varchar', nullable: false})
27
  private password: string;
28
29
  @Column({type: 'timestamp', nullable: true})
30
  private entryDate: string;
31
32
  @Column('enum', {enum: UserRole, nullable: false})
33
  private role: UserRole;
34
35
  @Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'})
36
  private createdAt: Date;
37
38
  constructor(
39
    firstName: string,
40
    lastName: string,
41
    email: string,
42
    apiToken: string,
43
    password: string,
44
    role: UserRole,
45
    entryDate?: string
46
  ) {
47
    this.firstName = firstName;
48
    this.lastName = lastName;
49
    this.email = email;
50
    this.apiToken = apiToken;
51
    this.password = password;
52
    this.role = role;
53
    this.entryDate = entryDate;
54
  }
55
56
  public getId(): string {
57
    return this.id;
58
  }
59
60
  public getFirstName(): string {
61
    return this.firstName;
62
  }
63
64
  public getLastName(): string {
65
    return this.lastName;
66
  }
67
68
  public getEmail(): string {
69
    return this.email;
70
  }
71
72
  public getApiToken(): string {
73
    return this.apiToken;
74
  }
75
76
  public getPassword(): string {
77
    return this.password;
78
  }
79
80
  public getEntryDate(): string {
81
    return this.entryDate;
82
  }
83
84
  public getRole(): UserRole {
85
    return this.role;
86
  }
87
88
  public getFullName(): string {
89
    return `${this.firstName} ${this.lastName}`;
90
  }
91
92
  public update(firstName: string, lastName: string, email: string): void {
93
    this.firstName = firstName;
94
    this.lastName = lastName;
95
    this.email = email;
96
  }
97
98
  public updatePassword(password: string): void {
99
    this.password = password;
100
  }
101
}
102